package com.baidu.emus;

public enum ErrorCode implements BaseEnum<Integer> {
	success(0, "操作成功" ), 
	loginFailed(1001, "用户名或密码错误"),//登陆失败
	captchaError(1002, "验证码错误"),//验证码错误
	registerError(1003, "注册信息有误"),//注册信息有误
	replyError(1004, "回帖设置有误");//回帖设置有误

	private int code;

	private String description;

	private ErrorCode(int _code, String description) {
		this.code = _code;
		this.description = description;
	}

	public Integer getCode() {
		return this.code;
	}

	public String getDescription() {
		return description;
	}

	@Override
	public String toString() {

		return String.valueOf(this.code);

	}

	// 通过属性获取对象
	public static ErrorCode getErrorCode(int code) {

		for (ErrorCode obj : ErrorCode.values()) {
			if (code == obj.getCode()) {

				return obj;
			}
		}

		return null;

	}

	public static String getName(int code) {

		for (ErrorCode obj : ErrorCode.values()) {
			if (code == obj.getCode()) {

				return obj.name();
			}
		}

		return null;

	}

	public static String getDescription(int code) {

		for (ErrorCode obj : ErrorCode.values()) {
			if (code == obj.getCode()) {

				return obj.getDescription();
			}
		}
		return null;

	}
}
